package com.grass.p019lv.novel.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.bean.novel.FictionBean;
import com.androidx.p013lv.base.bean.novel.FictionList;
import com.androidx.p013lv.base.dialog.BuyVipDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.grass.p019lv.databinding.ActivityFictionLabelBinding;
import com.grass.p019lv.novel.adapter.AudioFictionLabelAdapter;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

/* renamed from: com.grass.lv.novel.activity.VoiceNovelLabelActivity */
public class VoiceNovelLabelActivity extends BaseActivity<ActivityFictionLabelBinding> implements OnRefreshLoadMoreListener {
    AudioFictionLabelAdapter adapter;
    int page = 1;
    public int tagId;
    public String title;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_fiction_label;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityFictionLabelBinding) this.binding).toolbar).init();
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        this.title = getIntent().getStringExtra(Key.TITLE);
        this.tagId = getIntent().getIntExtra("tagId", -1);
        TextView textView = ((ActivityFictionLabelBinding) this.binding).tvTitle;
        textView.setText("#" + this.title);
        ((ActivityFictionLabelBinding) this.binding).refresh.setOnRefreshListener(this);
        ((ActivityFictionLabelBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((ActivityFictionLabelBinding) this.binding).tvBack.setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.novel.activity.VoiceNovelLabelActivity.View$OnClickListenerC31221 */

            public void onClick(View view) {
                VoiceNovelLabelActivity.this.finish();
            }
        });
        ((ActivityFictionLabelBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.adapter = new AudioFictionLabelAdapter();
        ((ActivityFictionLabelBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(new ItemClickListener() {
            /* class com.grass.p019lv.novel.activity.VoiceNovelLabelActivity.C31232 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                if (!VoiceNovelLabelActivity.this.isOnClick()) {
                    if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                        new BuyVipDialog(VoiceNovelLabelActivity.this.getActivity()).show();
                        return;
                    }
                    int fictionId = ((FictionList) VoiceNovelLabelActivity.this.adapter.getDataInPosition(i)).getFictionId();
                    Intent intent = new Intent(VoiceNovelLabelActivity.this.getActivity(), VoiceNovelActivityNew.class);
                    intent.putExtra(Key.NOVEL_ID, fictionId);
                    VoiceNovelLabelActivity.this.getActivity().startActivity(intent);
                }
            }
        });
        ((ActivityFictionLabelBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.novel.activity.VoiceNovelLabelActivity.View$OnClickListenerC31243 */

            public void onClick(View view) {
                VoiceNovelLabelActivity.this.page = 1;
                VoiceNovelLabelActivity.this.getInfo();
            }
        });
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.page == 1) {
            AudioFictionLabelAdapter audioFictionLabelAdapter = this.adapter;
            if (!(audioFictionLabelAdapter == null || audioFictionLabelAdapter.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((ActivityFictionLabelBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((ActivityFictionLabelBinding) this.binding).statusLayout.showLoading();
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getNovelTag(this.tagId, this.page, 30), new HttpCallback<BaseRes<FictionBean>>("VOICE_NOVEL_BY_TITLE") {
            /* class com.grass.p019lv.novel.activity.VoiceNovelLabelActivity.C31254 */

            public void onLvSuccess(BaseRes<FictionBean> baseRes) {
                if (VoiceNovelLabelActivity.this.binding != null) {
                    ((ActivityFictionLabelBinding) VoiceNovelLabelActivity.this.binding).statusLayout.hideLoading();
                    ((ActivityFictionLabelBinding) VoiceNovelLabelActivity.this.binding).refresh.finishRefresh();
                    ((ActivityFictionLabelBinding) VoiceNovelLabelActivity.this.binding).refresh.finishLoadMore();
                    if (baseRes.getCode() == 200) {
                        if (baseRes.getData() == null || baseRes.getData().getData() == null || baseRes.getData().getData().size() <= 0) {
                            if (VoiceNovelLabelActivity.this.page == 1) {
                                ((ActivityFictionLabelBinding) VoiceNovelLabelActivity.this.binding).statusLayout.showEmpty();
                            } else {
                                ((ActivityFictionLabelBinding) VoiceNovelLabelActivity.this.binding).refresh.finishLoadMoreWithNoMoreData();
                            }
                        } else if (VoiceNovelLabelActivity.this.page == 1) {
                            VoiceNovelLabelActivity.this.adapter.setDomain(baseRes.getData().getDomain());
                            VoiceNovelLabelActivity.this.adapter.setData(baseRes.getData().getData());
                            ((ActivityFictionLabelBinding) VoiceNovelLabelActivity.this.binding).refresh.resetNoMoreData();
                        } else {
                            VoiceNovelLabelActivity.this.adapter.setDatasInEnd(baseRes.getData().getData());
                        }
                    } else if (VoiceNovelLabelActivity.this.page == 1) {
                        ((ActivityFictionLabelBinding) VoiceNovelLabelActivity.this.binding).statusLayout.showError();
                    } else {
                        ToastUtils.getInstance().showWeak(baseRes.getMsg());
                    }
                }
            }
        });
    }

    @Override // androidx.fragment.app.FragmentActivity
    public void onResume() {
        super.onResume();
        getUserInfo();
    }

    public void getUserInfo() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userInfo(), JsonParams.build().commit(), new HttpCallback<BaseRes<UserInfo>>("userInfo") {
            /* class com.grass.p019lv.novel.activity.VoiceNovelLabelActivity.C31265 */

            public void onLvSuccess(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() == 200) {
                    SpUtils.getInstance().setUserInfo(baseRes.getData());
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        this.page++;
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        getInfo();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag("VOICE_NOVEL_BY_TITLE");
        HttpUtils.getInsatance().cancelTag("userInfo");
    }
}
